﻿Imports System.Windows.Forms
Imports C1.C1Zip
Public Class dlgZip
    Private m_FileName As String
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub cmbSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSet.Click
        Dim _appTitle As String = "C1Zip Demo"      ' the caption
        Dim _escape As Boolean = False              ' user hit escape
        Dim _cancel As Boolean = False              ' user wants to cancel
        ' show file open dialog
        Dim sf As SaveFileDialog = New SaveFileDialog()
        sf.DefaultExt = "zip"
        sf.Filter = "Zip Files (*.zip)|*.zip"
        If sf.ShowDialog() <> Windows.Forms.DialogResult.OK Then Return
        m_FileName = sf.FileName
        Me.TextBox1.Text = m_FileName

    End Sub

    Private Sub dlgZip_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub cmbZ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbZ.Click
        Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(AermodProject0.SaveName).DirectoryName
        Dim strNameLast As String = CAermod.GetFileName(AermodProject0.SaveName)

        Dim filses(-1) As String
        '气象方案
        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Aermet\" & "stage2.inp") Then
            ReDim Preserve filses(filses.Length)

            filses(0) = PrjPath & "\" & strNameLast & "\" & "Aermet\" & "stage2.inp"
        End If
        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Aermet\" & "stage3.inp") Then
            ReDim Preserve filses(filses.Length)

            filses(1) = PrjPath & "\" & strNameLast & "\" & "Aermet\" & "stage3.inp"
        End If
        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Aermet\" & "SF.OQA") Then
            ReDim Preserve filses(filses.Length)

            filses(2) = PrjPath & "\" & strNameLast & "\" & "Aermet\" & "SF.OQA"
        End If
        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Aermet\" & "UA.OQA") Then
            ReDim Preserve filses(filses.Length)
            filses(3) = PrjPath & "\" & strNameLast & "\" & "Aermet\" & "UA.OQA"
        End If

        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "Aermet\" & "OS.OQA") Then
            ReDim Preserve filses(filses.Length)
            filses(4) = PrjPath & "\" & strNameLast & "\" & "Aermet\" & "OS.OQA"

        End If
        '地形方案
        If AermodProject0.Aermap.Control.DataFile.Length > 0 And AermodProject0.Aermod.Control.AllPolluts.GenralPolluts.ArrayPollut(0).Dispersion.Flat = False Then
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermap.inp") Then
                ReDim Preserve filses(filses.Length)
                filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "Aermap.inp"
            End If
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermap\" & "0.dem") Then
                ReDim Preserve filses(filses.Length)
                filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "Aermap\" & "0.dem"
            End If
        End If
        '建筑物下洗方案
        If AermodProject0.Aermod.Bprm.ArryBldgi.Length > 0 And AermodProject0.Aermod.Control.AllPolluts.GenralPolluts.ArrayPollut(0).Dispersion.NoStd = False Then
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "bpipprm.inp") Then
                ReDim Preserve filses(filses.Length)
                filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "bpipprm.inp"
            End If
            If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "bpipprm.bat") Then
                ReDim Preserve filses(filses.Length)
                filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "bpipprm.bat"
            End If
        End If
        'Aermod气象文件
        If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermod\" & "aemodProf.PFL") Then
            ReDim Preserve filses(filses.Length)
            filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "Aermod\" & "aemodSurf.SFC"
        End If
        If My.Computer.FileSystem.FileExists(CAermod.Path.ModelsPath() & "Aermod\" & "aemodProf.PFL") Then
            ReDim Preserve filses(filses.Length)
            filses(filses.Length - 1) = CAermod.Path.ModelsPath() & "Aermod\" & "aemodProf.PFL"
        End If
        'Aermod方案文件
        For Each foundFile As String In My.Computer.FileSystem.GetFiles(PrjPath & "\" & strNameLast & "\" & "Aermod\", FileIO.SearchOption.SearchAllSubDirectories, "*.inp")
            ReDim Preserve filses(filses.Length)
            filses(filses.Length - 1) = foundFile
        Next
        'Aermod方案文件
        For Each foundFile As String In My.Computer.FileSystem.GetFiles(PrjPath & "\" & strNameLast & "\" & "Aermod\", FileIO.SearchOption.SearchAllSubDirectories, "*.out")
            ReDim Preserve filses(filses.Length)
            filses(filses.Length - 1) = foundFile
        Next
        AddFileList(filses, 0)

    End Sub
    ' add a list of files to the zip file, keeping the specified pathLevels
    Private Sub AddFileList(ByVal files() As String, ByVal pathLevels As Integer)
        'Dim _zipfile As C1ZipFile = New C1ZipFile()
        '' create a new empty zip file
        '_zipfile.Create(m_FileName)
        '' keep track of errors and time execution 
        'Dim err As String = ""
        'Dim start As Long = DateTime.Now.Ticks

        '' add files
        'Dim file As String
        'For Each file In files
        '    If file <> "" Then
        '        ' add the file 
        '        Dim x As Exception
        '        Try
        '            Me.Label2.Text = "正在打包" & file
        '            _zipfile.Entries.Add(file, pathLevels)
        '            Application.DoEvents()
        '        Catch x
        '            Me.Label2.Text = x.Message
        '            Exit Sub
        '        End Try
        '    End If
        'Next
        'Me.Label2.Text = "打包完毕"
    End Sub
End Class
